package net.xdclass.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.xdclass.mapper.LinkGroupMapper;
import net.xdclass.model.LinkGroupDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 小二
 */
@Component
public class LinkGroupManagerImpl implements net.xdclass.manager.LinkGroupManager {

    @Autowired
    private LinkGroupMapper linkGroupMapper;

    @Override
    public int add(LinkGroupDO linkGroupDO) {
        return linkGroupMapper.insert(linkGroupDO);
    }

    @Override
    public int del(Long groupId, long accountNo) {
        LambdaQueryWrapper<LinkGroupDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LinkGroupDO::getAccountNo, accountNo)
                .eq(LinkGroupDO::getId, groupId);
        return linkGroupMapper.delete(queryWrapper);
    }

    @Override
    public int update(LinkGroupDO linkGroupDO) {
        LambdaQueryWrapper<LinkGroupDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LinkGroupDO::getId, linkGroupDO.getId())
                .eq(LinkGroupDO::getAccountNo, linkGroupDO.getAccountNo());
        return linkGroupMapper.update(linkGroupDO, queryWrapper);
    }

    @Override
    public LinkGroupDO detail(Long groupId, long accountNo) {
        LambdaQueryWrapper<LinkGroupDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LinkGroupDO::getId, groupId)
                .eq(LinkGroupDO::getAccountNo, accountNo);
        return linkGroupMapper.selectOne(queryWrapper);
    }

    @Override
    public List<LinkGroupDO> listAllGroup(long accountNo) {
        LambdaQueryWrapper<LinkGroupDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LinkGroupDO::getAccountNo, accountNo);
        return linkGroupMapper.selectList(queryWrapper);
    }
}
